package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Salary;
import service.Service;

/**
 * Servlet implementation class SetBaseSalaryServlet
 */
@WebServlet("/SetBaseSalaryServlet")
public class SetBaseSalaryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SetBaseSalaryServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		int empId = Integer.parseInt(request.getParameter("empId"));
		double positionSal = Double.parseDouble(request.getParameter("positionSal"));
		double xinjiSal = Double.parseDouble(request.getParameter("xinjiSal"));
		double zhiwuSal = Double.parseDouble(request.getParameter("zhiwuSal"));
		Salary salary = new Salary();
		salary.setEmpId(empId);
		salary.setPositionSal(positionSal);
		salary.setXinjiSal(xinjiSal);
		salary.setZhiwuSal(zhiwuSal);
		Service s = new Service();
		if(s.updateBaseSalById(salary)) {
			request.getRequestDispatcher("a_other/success.jsp").forward(request, response);
		}
	}

}
